home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d26 / cc4.arc / DEMO4.CC < prev    next >
Encoding:
Text File  |  1991-04-14  |  4.1 KB  |  286 lines

  1. // Demonstration file for CC - Version 4
  2. 1
  3.  
  4. 1
  5. // This file demonstrates only those features  
  6. 1
  7.   that are new to Version 4.  You could run   
  8. 2
  9.   the demo file for Version 3 to see the      
  10. 3
  11.   original features of CC, but the 3D graphics
  12. 4
  13.   commands won't work.  We demonstrate their  
  14. 5
  15.   new syntax here.
  16. 6
  17.  
  18. 1
  19. // Matrices
  20. 1
  21.  
  22. 1
  23. A = {1,2,3;4,5,6;7,9,8}  // 3 x 3 matrix
  24. 1
  25.  
  26. 1
  27. B = A"                   // Transpose of A
  28. 1
  29.  
  30. 1
  31. A + B                    // Sum
  32. 1
  33.  
  34. 1
  35. A*B                      // Product
  36. 1
  37.  
  38. 1
  39. A^(-1)                   // inverse of A
  40. 1
  41.  
  42. 1
  43. A/B                      // A*B^(-1)
  44. 1
  45.  
  46. 1
  47. A\B                      // A^(-1)*B
  48. 1
  49.  
  50. 1
  51. A = Random(3,5)          // 3 x 5 matrix
  52. 1
  53.  
  54. 1
  55. B = RREF(A)              // Row reduced form 
  56. 1
  57.  
  58. 1
  59. C = B[1:3, 4:5]          // submatrix
  60. 1
  61.  
  62. 1
  63. H = Matrix(1/(i+j-1),i = 1 to 4, j = 1 to 4)
  64. 1
  65.                          // Hilbert Matrix
  66. 1
  67.  
  68. 1
  69. H^3                      // third power
  70. 1
  71.  
  72. 1
  73. 1/H                      // inverse of H
  74. 1
  75.  
  76. 1
  77. P = CharPoly(H)          // Characteristic     
  78. 1
  79.                            polynomial
  80. 2
  81.  
  82. 1
  83. E = EigenVal(H)          // Eigenvalues
  84. 1
  85.  
  86. 1
  87. Rank(H - E[1]*Eye(4))    // Should be 3, since
  88. 1
  89.                            matrix - eigenvalue
  90. 2
  91.                            is singular
  92. 3
  93.  
  94. 1
  95. // Big Numbers and Fractions
  96. 1
  97.  
  98. 1
  99. // A number preceded by & is called a Big      
  100. 1
  101.   Number and will be maintained to infinite   
  102. 2
  103.   precision.  All computations with Big       
  104. 3
  105.   Numbers and integers result in Big Numbers, 
  106. 4
  107.   and quotients of Big Numbers are stored as 
  108. 5
  109. // exact fractions reduced to lowest terms.
  110. 1
  111.  
  112. 1
  113. x = &3/&5                // fraction
  114. 1
  115.  
  116. 1
  117. y = &7/4 - &2/3          // exact arithmetic
  118. 1
  119.  
  120. 1
  121. z = &3^100               // big numbers
  122. 1
  123.  
  124. 1
  125. w = &100!                // very big numbers
  126. 1
  127.  
  128. 1
  129. H = Matrix(1/Fix(i+j-1),i = 1 to 4, j = 1 to 4)
  130. 1
  131.        // 4 x 4 Hilbert matrix.  The function  
  132. 1
  133.          FIX returns a Big Number.  Its       
  134. 2
  135.          complement is FLOAT
  136. 3
  137.  
  138. 1
  139. H*H                      // exact product
  140. 1
  141.  
  142. 1
  143. 1/H                      // exact inverse of H
  144. 1
  145.  
  146. 1
  147. //  New Three Dimensional Graphing Commands
  148. 1
  149.  
  150. 1
  151. // Version 3's 3d graphing commands have been  
  152. 1
  153.   simplified, and new commands have been      
  154. 2
  155.   added, in version 4.
  156. 3
  157.  
  158. 1
  159. Graph3d(x^2-y^2,x = -1 to 1, y = -1 to 1)
  160. 1
  161.     // no longer necessary to specify the third
  162. 1
  163.       limits or the number of steps
  164. 2
  165.  
  166. 1
  167. Paramg3d(sin(s)cos(t), sin(s)sin(t), cos(s),   
  168. 1
  169.      s = 0 to pi, t = 0 to 2pi)
  170. 2
  171.    // x,y,z limits and the number of steps     
  172. 1
  173.      need not be specified, 
  174. 2
  175.  
  176. 1
  177. Curve3d(cos(t), sin(t), t, t= 0 to 4pi)
  178. 1
  179.    // new command for parametric curves
  180. 1
  181.  
  182. 1
  183. Matrixg(h)
  184. 1
  185.   // New command:  Graph the data in a matrix
  186. 1
  187.  
  188. 1
  189. // New string operations
  190. 1
  191.  
  192. 1
  193. q1 = 'abc'|'de'   // concatenation
  194. 1
  195. q2 = q1[3]        // single character
  196. 1
  197. q3 = q1[2:4]      // substring
  198. 1
  199. q4 = upcase(q1)   // upper case transform
  200. 1
  201. n = pos('de',q1)  // position of substring
  202. 1
  203. m = asc(q1)       // list of ascii codes
  204. 1
  205. q5 = chr(m)       // characters from codes
  206. 1
  207. n1 = val('123 + cos(4)')                       
  208. 1
  209.                  // value of a string
  210. 2
  211. q6 = str(123+cos(4))                           
  212. 1
  213.                  // string from a value
  214. 2
  215.  
  216. 1
  217. // See subroutine for new input@ command
  218. 1
  219. intersect
  220. 1
  221.  
  222. 1
  223. // procedure demonstrating use of Input@
  224. 1
  225.  
  226. 1
  227. Procedure Intersect
  228. 1
  229.   // user finds intersection of two curves
  230. 1
  231.   Window(0,3,-1,1)
  232. 1
  233.   graphics
  234. 1
  235.   quickg(cos(x),x)
  236. 1
  237.   sk(x,x)
  238. 1
  239.   solve(cos(b)=b,b=1)   // target for user to guess
  240. 1
  241.   Write@(.1,-.5,'Move crosshairs to intersection of curves, and')
  242. 1
  243.   Write@(.1,-.6,'enter x-coordinate where curves intersect')
  244. 1
  245.   Repeat
  246. 1
  247.       input@(.3,-.8,5,x)
  248. 1
  249.       ok = x > b-0.05 and x < b+0.05 
  250. 1
  251.       if not ok
  252. 1
  253.           beep
  254. 1
  255.         end
  256. 1
  257.     until ok
  258. 1
  259.   write@(.1,-.7,x)
  260. 1
  261.   write@(.1,-.8,'You got it!!')
  262. 1
  263.   text
  264. 1
  265. end  // Intersect          
  266. 1
  267.         
  268. 1
  269.       
  270. 1
  271.       
  272. 1
  273.  
  274. 1
  275. input@(x,y)
  276. 1
  277.  
  278. 1
  279.  
  280. 1
  281.  
  282. 1
  283.